<template>
	<view class="container">
		
		<uni-group mode="card" :is-shadow="false" v-for="(item, index) in formList" :key="index">
			<history-form :formJson="item.formJson"></history-form>
		</uni-group>

	</view>
</template>

<script>
	import HistoryForm from '../components/historyForm.vue'
	import {
		getWorkFlowProcessList,
	} from "@/utils/api/api.js"
	
	import {
		transferFormData,
	} from "@/utils/utils.js"
	
	export default {
		data() {
			return {
				formList: [],
				workId: 0,
			}
		},
		onLoad(options) {
			this.workId = options.workId;
		},
		onShow() {
			
		},
		onReady() {
			this.init()
		},
		components: {
			HistoryForm,
		},
		methods: {
            //第一次调用
			init() {
				if (this.workId){
					let data = {
						workId: this.workId
					}
					getWorkFlowProcessList(data).then(res => {
						if (res.code == 1) {
							res.data.forEach((item) => {
							  let historyFormJson = JSON.parse(item.form.jsonData);
							  let historyFormData = item.formData ? item.formData : {};
							  let widgetArr = []; // 表单组件数组，不包含grid、table、tab、card等组件
							  // 数据格式处理
							  transferFormData(historyFormData, historyFormJson.widgetList, widgetArr);
							  widgetArr.push({ "type":"input","icon":"text-field","formItemFlag":true,"options":
							  {"name":"inputSubmitter","label":"提交人","labelAlign":"","type":"text","defaultValue":item.form.submitterName,"columnWidth":"200px" }});
							  widgetArr.push({ "type":"input","icon":"text-field","formItemFlag":true,"options":
							  {"name":"inputSubmitTime","label":"提交时间","labelAlign":"","type":"text","defaultValue":item.form.submitTime,"columnWidth":"200px" }});
							  this.formList.push({formJson: widgetArr});
							});
						} else {
							uni.showToast({
								title: res.msg,
								duration: 2000,
								mask: true,
								icon: 'none'
							});
						}
					})
				}
			},
		}
	}
</script>

<style>
	.container {
		font-size: 14px;
		line-height: 24px;
	}
</style>
